import java.util.Arrays;

abstract class Player {
    private static final int HAND_SIZE = 4;
	private Hand hand;
	private boolean hasFolded;
//	private boolean hasChecked;
	private int myBet;
	private int cash;
	private boolean hasQuit;
	Player(int startamount) {
		hand = new Hand();
		hasFolded = false;
//		hasChecked = false;           // tu uwaga
		myBet = 0;
		cash = startamount;
		hasQuit = false;
	}
	
	void resetFlags() {
	    hasFolded = false;
//	    hasChecked = false;
	    myBet = 0;
	}
	
	boolean hasFolded() {
	    return hasFolded;
	}
	
	int getCash() {
	    return cash;
	}
	
	boolean hasQuit() {
	    return hasQuit;
	}
	void quit() {
	    hasQuit = true;
	}
	
	void addToMyBet(int add) {
	    myBet += add;
	}
	
	void addToCash(int add) {
	    cash += add;
	}
	
	//void bet() {
	//    hasChecked = false;
	//}
	
	//void check() {
	//    hasChecked = true;
	//}
	
	void fold() {
	    hasFolded = true;
	}
	
	//boolean hasChecked() {
	//    return hasChecked;
	//}
	
	int myBet() {
	    return myBet;
	}
	
	void receiveCards(final Deck deck) {
		if (hand == null) {
            hand = new Hand();
        }
		for (int i = 0; i < HAND_SIZE; i++) {
            hand.cardPick(deck);
        }
	}
	void exchangeCards(final int[] picks, final Deck deck) {
		int len = picks.length;
		Arrays.sort(picks);
		for (int i = len - 1; i >= 0; i--) {
            hand.cardRemove(picks[i], deck);
        }
		for (int i = 0; i < len; i++) {
            hand.cardPick(deck);
        }
	}
	Hand getHand() {
		return hand;
	}
	int evaluateHand() {
		try {
			return hand.getHandRank();
		} catch (BadugiException e) {
			System.out.println(e.getMessage());
			e.printStackTrace();
			return 0;
		}
	}
	public String toString() {
		if (hand == null) {
            return "This player wasn't dealed";
        } else {
            return hand.toString();
        }
	}
	void discardHand() {
		hand = null;
	}
	boolean find(final int query, final int[] array, final int size) {
		boolean result = false;
		for (int i = 0; i < size; i++) {
			if (array[i] == query) {
				result = true;
				break;
			}
		}
		return result;
	}
	public abstract int[] picks();
	public abstract int getDecision(int maxbet, boolean allIn) throws BadugiException ;
}
